import QtQuick 1.1
import com.nokia.symbian 1.1
import QtWebKit 1.0

Page {
    id: browserPage
    tools: browserTools
    anchors.top: statusBar.bottom
    width: appWindow.width

    property string normalUrl : ""

    function startup(url) {
        normalUrl = url
        webView.url = "http://www.readability.com/m?url=" + url
    }

    function startSpinner() {
        browserLoadingSpinner.running = true;
        browserLoadingSpinner.visible = true;
    }

    function stopSpinner() {
        browserLoadingSpinner.visible = false
        browserLoadingSpinner.running = false
    }

    Flickable {
        id: flickable
        anchors.fill: parent

        flickableDirection: Flickable.VerticalFlick
        contentWidth: webView.width
        contentHeight: webView.height

        WebView {
            id: webView
            // width: appWindow.width
            preferredWidth: appWindow.width
            onLoadFinished: stopSpinner()
            onLoadStarted: startSpinner()
            onProgressChanged: visible = true
        }
    }

    BusyIndicator {
        id: browserLoadingSpinner
        running: false
        visible: false
        anchors.centerIn: parent
        platformInverted: appWindow.platformInverted
        width: 50
        height: 50
    }


    ToolBarLayout {
        id: browserTools
        visible: true
        ToolButton {
            iconSource: "toolbar-back";
            platformInverted: appWindow.platformInverted
            onClicked: { webView.url = "about:blank"; pageStack.pop();}
        }

        ToolButton {
             id: settingsIcon
             iconSource: "toolbar-menu";
             platformInverted: appWindow.platformInverted
             // anchors.right: parent===undefined ? undefined : parent.right
             onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
        }

    }


    Menu {
        id: myMenu
        visualParent: pageStack
        platformInverted: appWindow.platformInverted
        MenuLayout {
            MenuItem {
                id:openExternallyButton
                platformInverted: appWindow.platformInverted;
                text: 'Open in browser'
                onClicked: Qt.openUrlExternally(normalUrl);
            }
        }
    }
}
